package com.boc.langxiang.ui.activity.me;

import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import com.boc.langxiang.App;
import com.boc.langxiang.R;
import com.boc.langxiang.contract.common.AccountUpdateSexContract;
import com.boc.langxiang.presenter.common.AccountUpdateSexPresenter;
import com.boc.langxiang.util.T;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SetModifyGenderActivity extends MeBaseToolBarActivity implements AccountUpdateSexContract.View {


    @BindView(R.id.rb_me_set_boy)
    RadioButton rbMeSetBoy;
    @BindView(R.id.rb_me_set_girl)
    RadioButton rbMeSetGirl;
    @BindView(R.id.rg_me_set_gender)
    RadioGroup rgMeSetGender;
    private AccountUpdateSexPresenter mPresenter;

    private String mGenderText = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_set_modify_gender);
        ButterKnife.bind(this);
        setToolBarTitle("修改性別");

        initEvent();
        mPresenter = new AccountUpdateSexPresenter(this);
    }

    private void initEvent() {
        rgMeSetGender.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                int checkedRadioButtonId = group.getCheckedRadioButtonId();
                RadioButton checkButton = (RadioButton) group.findViewById(checkedRadioButtonId);
                mGenderText = checkButton.getText().toString();
            }
        });
    }


    @Override
    protected int setToolBarBackgroundColor() {
        return Color.WHITE;
    }

    @Override
    protected int setToolBarBackImg() {
        return R.drawable.icon_me_left;
    }

    @Override
    protected int setToolBarTitleColor() {
        return Color.BLACK;
    }

    @Override
    public void showLoading() {
        showProgressDialog();
    }

    @Override
    public void hideLoading() {
        hideDialog();
    }

    @Override
    public void onError(String code, String msg) {
        T.showShort(mContext, msg);
    }


    @OnClick(R.id.btn_me_set_commitgender)
    public void onClick() {

        if (TextUtils.isEmpty(mGenderText)) {
            Toast.makeText(App.getInstance(), "请选择性别", Toast.LENGTH_SHORT).show();
            return;
        }
        Log.d("SetModifyGenderActivity", mGenderText);
        mPresenter.accountUpdateSex(mGenderText);
    }

    @Override
    public void endActivity() {
        finish();
    }
}
